﻿using System;
using RazakiBLL;
using RazakiSite.Classes;

namespace RazakiSite
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            //set caching instance:
            UtilitiesBLL.CacheProvider = new CacheProvider();
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            UtilitiesUI.VisitorsCountManager(1);
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

#if !DEBUG
            // Get the exception object.
            Exception exc = Server.GetLastError();

            ExceptionManager.Log(exc);

            //(fn.) masire page marbut be error az web.config mikhanad.
            //Redirect HTTP errors to HttpError page
            Server.Transfer(string.Empty);

            // Clear the error from the server
            Server.ClearError();
#endif

        }

        protected void Session_End(object sender, EventArgs e)
        {
            //در این قسمت 
            //HttpContext.Current
            //برابر با
            //null
            //است
            //به همین دلیل
            //Application
            //فرستاده شده است
            UtilitiesUI.VisitorsCountManager(-1, Application);
        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}